--TEST--
string MySQLndUhConnection::getErrorString(resource $connection)
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
	require_once('config.inc');

	class proxy extends MySQLndUhConnection {
		public function getErrorString($res) {
			printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));
			var_dump($ret = parent::getErrorString($res));
			return $ret;
		}
	}

	class proxy2 extends MySQLndUhConnection {
		public function getErrorString($res) {
			return "my error";
		}
	}

	class proxy3 extends MySQLndUhConnection {
		public function getErrorString($res) {
			$ret = array();
			return $ret;
		}
	}

	class proxy4 extends MySQLndUhConnection {
		public function getErrorString($res) {}
	}

	class proxy5 extends MySQLndUhConnection {
		public function getErrorString($res) {
			return str_repeat("a", 4096);
		}
	}


	$conn = mysqlnd_uh_test\connect::mysqli();
	mysqlnd_uh_test\query_test::mysqli($conn);
	$conn->kill($conn->thread_id);
	var_dump($conn->query("SELECT 1 FROM DUAL"));
	$err = $conn->error;

	$conn = mysqlnd_uh_test\connect::mysqli();
	mysqlnd_uh_set_connection_proxy(new proxy());
	mysqlnd_uh_test\query_test::mysqli($conn);
	$conn->kill($conn->thread_id);
	var_dump($conn->query("SELECT 1 FROM DUAL"));

	if (($tmp = $conn->error) != $err)
		printf("[001] Error string has changed from %s to %s\n", $err, $tmp);

	if (($tmp2 = $conn->error) != $err)
		printf("[002] Error string has changed from %s to %s\n", $err, $tmp2);

	var_dump($conn->query("SELECT 1 FROM DUAL"));

	if (($tmp = $conn->error) != $err)
		printf("[003] Error string has changed from %s to %s\n", $err, $tmp);

	$conn = mysqlnd_uh_test\connect::mysqli();
	mysqlnd_uh_set_connection_proxy(new proxy2());
	var_dump($conn->error);

	mysqlnd_uh_set_connection_proxy(new proxy3());
	var_dump($conn->error);

	mysqlnd_uh_set_connection_proxy(new proxy4());
	var_dump($conn->error);

	mysqlnd_uh_set_connection_proxy(new proxy5());
	var_dump($conn->error);

	print "done!";
?>
--EXPECTF--
bool(false)
bool(false)
proxy::getErrorString(array (
  0 => NULL,
))
string(%d) "%s"
proxy::getErrorString(array (
  0 => NULL,
))
string(%d) "%s"
bool(false)
proxy::getErrorString(array (
  0 => NULL,
))
string(%d) "%s"
proxy::getErrorString(array (
  0 => NULL,
))
string(0) ""
string(8) "my error"

Warning: main(): (MySQLnd User Handler) The method MySQLndUhConnection::getErrorString() did not return a string value as it should in %s on line %d
NULL

Warning: main(): (MySQLnd User Handler) The method MySQLndUhConnection::getErrorString() did not return a string value as it should in %s on line %d
NULL

Warning: main(): (MySQLnd User Handler) The method MySQLndUhConnection::getErrorString() should not return a string longer than MYSQLND_UH_ERRMSG_SIZE - 1 characters. The return value will be trimmed in %s on line %d
string(%d) "%s"
done!